package cn.easytogo.action;

import java.io.IOException;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import cn.easytogo.bean.User;
import cn.easytogo.util.ConfigUtil;

public class BaseAction implements SessionAware, ServletRequestAware ,ServletResponseAware{
	public HttpServletRequest request;
	public Map<String, Object> session;
	public HttpServletResponse response;
	public User logedUser;
	private String successAlert = ConfigUtil.getConfigByName("success_alert");
	private String default_usergroup_id = ConfigUtil.getConfigByName("default_usergroup_id");
	
	public void setSession(Map<String, Object> arg0) {
		this.session = arg0;
		if(logedUser==null){//在加载session之后,将已登录用户的信息加载
			logedUser = (User) session.get(ConfigUtil.getConfigByName("session_name"));
		}
	}
	public void print(String str){
		response.setContentType("application/x-json; charset=utf-8");   
        response.setHeader("pragma","no-cache");   
        response.setHeader("cache-control","no-cache");   
		try {
			response.getWriter().print(str);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void setServletRequest(HttpServletRequest arg0) {
		this.request = arg0;
	}

	public void setServletResponse(HttpServletResponse arg0) {
		this.response = arg0;
	}
	public String getSuccessAlert() {
		return successAlert;
	}
	public void setSuccessAlert(String successAlert) {
		this.successAlert = successAlert;
	}
	public String getDefault_usergroup_id() {
		return default_usergroup_id;
	}
	public void setDefault_usergroup_id(String defaultUsergroupId) {
		default_usergroup_id = defaultUsergroupId;
	}
	protected ServletContext getServletContext()
    {
        return ServletActionContext.getServletContext();
    }
}
